$MOD51
	ORG	00H
MAIN:


lcall	kieu_1 ;goi chuong trinh


ljmp main
;-------ket thuc chuong trinh chinh


kieu_1:;chuong trinh con

	MOV	R1,#00H
	;TAT TAT CA CAC PORT
	mov 	p0,#00H 
	MOV	P1,#00H
	MOV	P2,#00H
	MOV 	P3,#00H
STAR1:
	
     
     
      ;DIEU KHIEN PORT 1
	MOV	DPTR,#DATADISP1 ;CSDL DIEU KHIEN CAC BIT
	MOV	A,R1
	MOVC	A,@A+DPTR
	MOV	P1,A ; PORT DUOC NAP DU LIEU VAO



lcall kieu_vien





;   LCALL	DELAY1




INC R1
CJNE	R1,#32,star1 ;THAY DOI SO NAY THEO CSDL
RET	
;--------------------------------------

kieu_vien:					;chuong trinh con

	MOV	R0,#00H
STAR2:
	MOV	DPTR,#DATADISP2 ;CSDL DIEU KHIEN CAC BIT
	MOV	A,R0
	MOVC	A,@A+DPTR
	MOV	P0,A ; PORT DUOC NAP DU LIEU VAO




LCALL	DELAY2
INC R0
CJNE	R0,#8,star2 ;THAY DOI SO NAY THEO CSDL
RET	

;------------------------


;nhom lenh cac vong lap
DELAY1:
	PUSH	00H
	MOV	R0,#70
	MOV	TMOD,#01H
LOOP1:
	MOV	TH0,#HIGH(-3000)	;CHINH TOC DO
	MOV	TL0,#LOW(-3000)	;CHINH TOC DO
	SETB	TR0
 	JNB	TF0,$
	CLR	TR0
	CLR	TF0
	DJNZ	R0,LOOP1
	POP	00H
	RET

DELAY2:
	PUSH	00H
	MOV	R0,#70
	MOV	TMOD,#01H
LOOP2:
	MOV	TH0,#HIGH(-800);CHINH TOC DO
	MOV	TL0,#LOW(-800);CHINH TOC DO
	SETB	TR0
 	JNB	TF0,$
	CLR	TR0
	CLR	TF0
	DJNZ	R0,LOOP2
	POP	00H
	RET
;------------------------
;du lieu dung de dieu khien
;csdl cong 1

DATADISP1:
DB	00000001B,00000010B,00000100B,00001000B,00010000B,00100000B,01000000B,10000000B,
DB	00000001B,00000010B,00000100B,00001000B,00010000B,00100000B,01000000B,10000000B,
DB	11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,
DB	11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,11111111B,00000000B,
DATADISP2:
DB	00000001B,00000010B,00000100B,00001000B,00000001B,00000010B,00000100B,00001000B,
END


